package oop.ex3.filemanager;

import java.io.File;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;

public class FileInfo {
	
	private String _dir;
	private String _file;
	public volatile AtomicInteger _numOfUploads; 
	private Object _deleteLock;
	
	public FileInfo(String file, String dir){
		_dir = dir;
		_numOfUploads = new AtomicInteger();
		_file = file;
		_deleteLock = new Object();
	}
	
	public Object getLock(){
		return _deleteLock;
	}
	
	public void deleteFile(){
		File file = new File(_dir+File.separator+_file);
		file.delete();
	}
	
	public File getFile(){
		File file = new File(_dir+File.separator+_file);
		return file;
	}
	
	public boolean renameFile(File newName){
		File file = new File(_dir+File.separator+_file);
		return file.renameTo(newName);
	}
	
	public String getFileName(){
		return _file;
	}
	
	public void addUpload(){
		_numOfUploads.addAndGet(1);
	}

	public void substructUpload() {
		_numOfUploads.decrementAndGet();
	}


}
